"""url：http://8.140.193.160:8899/admin/home/
账号admin   920509
作业：
1、登录——》新建用户分组——》删除用户分组
2、登录——》新增客服话术——》删除客服话术

搭建自动化测试框架，通用业务解耦完成
"""
import time
from crmeb_base.base import BaseApi
from selenium.webdriver.common.by import By
import allure
from faker import Faker
faker1 = Faker(locale='zh_cn')

user_text =(By.TAG_NAME,"input") #用户搜索框
password_text =(By.TAG_NAME,"input") #密码搜索框
Captcha_text =(By.TAG_NAME,"input") #验证码搜索框
input_groupname=(By.TAG_NAME,'input')
login_button = (By.CLASS_NAME,'btn') #登录按钮

click_user = (By.XPATH,"//*[@id='app']/div/div[1]/div[1]/div/ul/li[4]/div") #点击用户
click_usergroup= (By.XPATH,"//*[@id='app']/div/div[1]/div[1]/div/ul/li[4]/ul/li[2]") #点击用户分组
click_addusergroup =(By.XPATH,"//*[@id='app']/div/div[2]/div[2]/div/div[2]/div/div[2]/div/div[1]/div/button/span") #点击添加分组
click_addusergroup_name = (By.XPATH,"//input[@placeholder='请输入分组名称']") #点击添加分组的名称
click_tijiao = (By.CLASS_NAME,"ivu-btn") #点击提交
click_delete_button =(By.XPATH,"//*[@id='app']/div/div[2]/div[2]/div/div[2]/div/div[2]/div/div[2]/div[1]/div[4]/div[2]/table/tbody/tr[1]/td[1]/div/div/a[2]") #点击删除
click_queren = (By.CLASS_NAME,"ivu-btn") #点击确认

@allure.feature("crmeb-新建分组-删除分组")
class Delete_user_group(BaseApi):
    @allure.step("登录功能")
    def input_user_text(self):
        self.inputs_text(user_text,0,"admin")
    def input_mima_text(self):
        self.inputs_text(password_text,1,"920509")
    def input_yanzhengma_text(self):
        self.inputs_text(Captcha_text,2,"a")
    @allure.step('点击登录按钮')
    def click_search_button(self):
        self.click_element(login_button)
    @allure.step('点击用户')
    def click_yonghu(self):
        self.click_element(click_user)
    @allure.step('点击用户分组')
    def click_yonghufenzu(self):
        self.click_element(click_usergroup)
    @allure.step('点击添加分组')
    def click_addyonghufenzu(self):
        self.click_element(click_addusergroup)
    @allure.step('点击填写分组名称')
    def click_inputgroupname(self):
        time.sleep(2)
        self.input_text(click_addusergroup_name,f'{faker1.name()}')
    @allure.step("提交用户分组")
    def click_usergroupput(self):
        time.sleep(2)
        self.click_elements(click_tijiao,4)
    @allure.step("删除用户分组")
    def click_delete(self):
        self.click_element(click_delete_button)
    @allure.step("确定删除用户分组")
    def click_deleteconfir(self):
        self.click_elements(click_queren,5)


